package com.yonyougov.devops.cruxcisupport.backupuser;

import com.yonyougov.devops.cruxcisupport.backupuser.vo.BackupUserVo;
import com.yonyougov.devops.fwc.core.dao.impl.BaseDaoImpl;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.math.BigInteger;
import java.util.List;

/**
 * 备用测试人员 表数据层实现
 */
@Slf4j
@Repository
public class BackupTestUserDaoImpl extends BaseDaoImpl<BackupTestUserEntity, BigInteger> implements BackupTestUserDao {
    //<!--用户自定义代码开始-->
    private final SqlSessionTemplate sqlSessionTemplate;

    public BackupTestUserDaoImpl(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }

    @Override
    public boolean addBatch(List<BackupTestUserEntity> backupTestUserEntityList) {
        try {
            String statement = BackupTestUserEntity.class.getName() + "Mapper.addBatch";
            sqlSessionTemplate.insert(statement, backupTestUserEntityList);
        } catch (Exception e) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            log.error("addBatch BackupTestUserEntity get Exception is {}", sw.toString());
            return false;
        }
        return true;
    }

    @Override
    public List<BackupUserVo> getBackUserByCommitTestId(BigInteger commitTestId) {
        String statement = BackupTestUserEntity.class.getName() + "Mapper.getBackUserByCommitTestId";
        return sqlSessionTemplate.selectList(statement, commitTestId);
    }
    //<!--用户自定义代码结束-->
}
